package array.easy;

public class LeetCode495 {

    public int findPoisonedDuration(int[] timeSeries, int duration) {
        int res = 0;

        if (timeSeries.length == 1) {
            return duration;
        }

        for (int i = 1; i < timeSeries.length; i++) {
            int a = timeSeries[i] - timeSeries[i - 1];
            if (a < duration) {
                res += a;
            } else {
                res += duration;
            }
        }
        return res + duration;
    }
}
